﻿using System;
using Algoritmia.DataStructures.Trees;

namespace Algoritmia.Problems.RegularExpressions
{
    public class RegExpTree : BinaryTree
    {
        public string Literal { get; private set; }

        public RegExpTree(string op, RegExpTree left = null, RegExpTree right = null)
        {
            Literal = op;
            AppendLeft(left);
            AppendRight(right);
        }

        public new RegExpTree Left
        {
            get { return (RegExpTree) base.Left; }
        }

        public new RegExpTree Right
        {
            get { return (RegExpTree) base.Right; }
        }

        public override string ToString()
        {
            if (Left == null)
            {
                return Right == null
                           ? String.Format("[{0}]", Literal)
                           : String.Format("[{0}, ,{1}]", Literal, Right);
            }
            return String.Format("[{0}, {1}, {2}]", Literal, Left, Right == null ? "[]" : Right.ToString());
        }
    }
}
